package com.aliang.docker.service.impl;

import com.aliang.docker.config.StringUtils;
import com.aliang.docker.config.UserConstants;
import com.aliang.docker.entity.ClassiFication;
import com.aliang.docker.entity.TUser;
import com.aliang.docker.mapper.ClassiFicationMapper;
import com.aliang.docker.mapper.TUserMapper;
import com.aliang.docker.service.ClassiFicationService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassiFicationServiceImpl  extends ServiceImpl<ClassiFicationMapper, ClassiFication> implements ClassiFicationService {

    @Autowired
    private ClassiFicationMapper classif;
    @Override
    public List<ClassiFication> findName(){
        return classif.selectFica();
    }

    @Override
    public int insertPost(ClassiFication addFica) {
        return classif.insertFica(addFica);
    }


    /**
     * 校验分类名称是否唯一
     *
     * @param addFica 分类信息
     * @return 结果
     */
    @Override
    public String checkClassiNameUnique(ClassiFication addFica)
    {
        Long addId = StringUtils.isNull(addFica.getId()) ? -1L : addFica.getId();
        ClassiFication info = classif.checkClassiNameUnique(addFica.getName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != addId.longValue())
        {
            return UserConstants.POST_NAME_NOT_UNIQUE;
        }
        return UserConstants.POST_NAME_UNIQUE;
    }
}
